home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / misc / emu / amiSPIMsrc.lha / buttons.c < prev    next >
C/C++ Source or Header  |  1994-01-17  |  51KB  |  2,000 lines

  1. /* SPIM S20 MIPS simulator.
  2.    X interface to SPIM
  3.    (Derived from an earlier work by Alan Siow.)
  4.    Copyright (C) 1990-1994 by James Larus (larus@cs.wisc.edu).
  5.    ALL RIGHTS RESERVED.
  6.  
  7.    SPIM is distributed under the following conditions:
  8.  
  9.      You may make copies of SPIM for your own use and modify those copies.
  10.  
  11.      All copies of SPIM must retain my name and copyright notice.
  12.  
  13.      You may not sell SPIM or distributed SPIM in conjunction with a
  14.      commerical product or service without the expressed written consent of
  15.      James Larus.
  16.  
  17.    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  18.    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  19.    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.    PURPOSE. */
  21.  
  22.  
  23. /* $Header: /home/primost/larus/Software/SPIM/RCS/buttons.c,v 3.38 1994/01/18 03:21:45 larus Exp larus $
  24.  */
  25.  
  26. #include <X11/Intrinsic.h>
  27. #include <X11/StringDefs.h>
  28. #include <X11/Shell.h>
  29. #include <X11/Xaw/Form.h>
  30. #include <X11/Xaw/AsciiText.h>
  31. #include <X11/Xaw/Command.h>
  32. #include <X11/Xaw/Dialog.h>
  33. #include <X11/Xaw/Label.h>
  34. #include <X11/Xaw/MenuButton.h>
  35. #include <X11/Xaw/SimpleMenu.h>
  36. #include <X11/Xaw/Sme.h>
  37. #include <X11/Xaw/SmeBSB.h>
  38. #include <X11/Xaw/Cardinals.h>
  39.  
  40. #include <stdio.h>
  41. #include <setjmp.h>
  42. #include <ctype.h>
  43.  
  44. #include "spim.h"
  45. #include "spim-utils.h"
  46. #include "xspim.h"
  47. #include "inst.h"
  48. #include "mem.h"
  49. #include "reg.h"
  50. #include "scanner.h"
  51. #include "sym-tbl.h"
  52. #include "buttons.h"
  53.  
  54. #ifdef CL_SPIM
  55. #include "cl-cache.h"
  56. #include "cl-cycle.h"
  57. #include "cl-tlb.h"
  58. #include "cl-except.h"
  59. #include "mips-syscall.h"
  60. #endif
  61.  
  62.  
  63. /* Local functions: */
  64.  
  65. #ifdef __STDC__
  66. static void add_breakpoint_action (Widget w, XtPointer client_data,
  67.     XtPointer call_data);
  68. static void add_clear_button (Widget parent);
  69. static void add_mode_button (Widget parent);
  70. static void add_print_button (Widget parent);
  71. static void add_terminal_button (Widget parent);
  72. static void breakpoint_prompt (Widget button, XtPointer client_data,
  73.                    XtPointer call_data);
  74. static void breakpoint_prompt_destroyed (Widget w, XtPointer client_data,
  75.                      XtPointer call_data);
  76. static void clear_program_state_action (Widget w, XtPointer client_data,
  77.                     XtPointer call_data);
  78. static void continue_action (Widget w, XtPointer client_data,
  79.                  XtPointer call_data);
  80. static void continue_prompt_destroyed (Widget w, XtPointer client_data,
  81.                        XtPointer call_data);
  82. static void delete_breakpoint_action (Widget w, XtPointer client_data,
  83.                       XtPointer call_data);
  84. static void destroy_popup_prompt (Widget w, XtPointer client_data,
  85.                   XtPointer call_data);
  86. static void help_action (Widget w, XtPointer ignore, XtPointer ignored);
  87. static void init_stack (char *args);
  88. static void load_prompt (Widget button, XtPointer client_data,
  89.              XtPointer call_data);
  90. static void load_prompt_destroyed (Widget w, XtPointer client_data,
  91.                    XtPointer call_data);
  92. static void list_breakpoint_action (Widget w, XtPointer client_data,
  93.                     XtPointer call_data);
  94. static void noop (void);
  95. static void parse_print_value (Widget w, XtPointer client_data,
  96.                    XtPointer call_data);
  97. static void parse_set_value (Widget w, XtPointer client_data,
  98.                  XtPointer call_data);
  99. static Widget popup_two_field_dialog (Widget button, String name,
  100.                       String field1_label, String field1_value,
  101.                       String field2_label, String field2_value,
  102.                       String action_name,
  103.                       void (*action) (/* ??? */),
  104.                       String action2_name,
  105.                       void (*action2) (/* ??? */),
  106.                       Widget *field1_text,
  107.                       Widget *field2_text);
  108. static void print_mem_prompt (Widget button, XtPointer client_data,
  109.                   XtPointer call_data);
  110. static void print_prompt_destroyed (Widget w, XtPointer client_data,
  111.                     XtPointer call_data);
  112. static void print_symbol_action (Widget w, XtPointer client_data,
  113.                  XtPointer call_data);
  114. static void quit_action (Widget w, XtPointer client_data,XtPointer call_data);
  115. static void quit_prompt (Widget button, XtPointer client_data,
  116.              XtPointer call_data);
  117. static void quit_prompt_destroyed (Widget w, XtPointer client_data,
  118.                    XtPointer call_data);
  119. static void read_assm_file_action (Widget w, XtPointer client_data,
  120.                    XtPointer call_data);
  121. static void read_exec_file_action (Widget w, XtPointer client_data,
  122.                    XtPointer call_data);
  123. static void run_program_action (Widget w, XtPointer client_data,
  124.                 XtPointer call_data);
  125. static void run_prompt (Widget button, XtPointer client_data,
  126.             XtPointer call_data);
  127. static void run_prompt_destroyed (Widget w, XtPointer client_data,
  128.                   XtPointer call_data);
  129. static void select_mode_action (Widget w, XtPointer client_data,
  130.                 XtPointer call_data);
  131. static void set_value_action (char *location_str,char *value_str);
  132. static void set_value_prompt (Widget button, XtPointer client_data,
  133.                   XtPointer call_data);
  134. static void set_value_destroyed (Widget w, XtPointer client_data,
  135.                  XtPointer call_data);
  136. static void step_continue_action (Widget w, XtPointer client_data,
  137.                   XtPointer call_data);
  138. static void step_program_action (Widget w, XtPointer client_data,
  139.                  XtPointer call_data);
  140. static void step_prompt (Widget button, XtPointer client_data,
  141.              XtPointer call_data);
  142. static void step_prompt_destroyed (Widget w, XtPointer client_data,
  143.                    XtPointer call_data);
  144. static void warp_to_second_dialog (Widget widget, XEvent *event,
  145.                    String *params, Cardinal *num_params);
  146.  
  147. #ifdef CL_SPIM
  148. static void add_cache_button (Widget parent);
  149. static void add_info_button (Widget parent);
  150. static void cl_cycle_mode_action (Widget choice, XtPointer client_data,
  151.                   XtPointer call_data);
  152. static void cl_dcache_mode_action (Widget choice, XtPointer client_data,
  153.                    XtPointer call_data);
  154. static void cl_icache_mode_action (Widget choice, XtPointer client_data,
  155.                    XtPointer call_data);
  156. static void cl_reinit_prompt_destroyed (Widget w, XtPointer client_data,
  157.                     XtPointer call_data);
  158. static void cl_reinit_prompt (char *str, void (*callback)());
  159. static void dcache_action (Widget button, XtPointer client_data,
  160.                XtPointer call_data);
  161. static void icache_action (Widget button, XtPointer client_data,
  162.                XtPointer call_data);
  163. static void info_action (Widget w, XtPointer client_data, XtPointer call_data);
  164. static void pipe_action (Widget button, XtPointer client_data,
  165.              XtPointer call_data);
  166. #endif
  167.  
  168. #else
  169.  
  170. static void add_breakpoint_action ();
  171. static void add_clear_button ();
  172. static void add_mode_button ();
  173. static void add_print_button ();
  174. static void add_terminal_button ();
  175. static void breakpoint_prompt ();
  176. static void breakpoint_prompt_destroyed ();
  177. static void clear_program_state_action ();
  178. static void continue_action ();
  179. static void continue_prompt_destroyed ();
  180. static void delete_breakpoint_action ();
  181. static void destroy_popup_prompt ();
  182. static void help_action ();
  183. static void init_stack ();
  184. static void load_prompt ();
  185. static void load_prompt_destroyed ();
  186. static void list_breakpoint_action ();
  187. static void noop ();
  188. static void parse_print_value ();
  189. static void parse_set_value ();
  190. static Widget popup_two_field_dialog ();
  191. static void print_mem_prompt ();
  192. static void print_prompt_destroyed ();
  193. static void print_symbol_action ();
  194. static void quit_action ();
  195. static void quit_prompt ();
  196. static void quit_prompt_destroyed ();
  197. static void read_assm_file_action ();
  198. static void read_exec_file_action ();
  199. static void run_program_action ();
  200. static void run_prompt ();
  201. static void run_prompt_destroyed ();
  202. static void select_mode_action ();
  203. static void set_value_action ();
  204. static void set_value_prompt ();
  205. static void set_value_destroyed ();
  206. static void step_continue_action ();
  207. static void step_program_action ();
  208. static void step_prompt ();
  209. static void step_prompt_destroyed ();
  210. static void warp_to_second_dialog ();
  211.  
  212. #ifdef CL_SPIM
  213. static void add_cache_button ();
  214. static void add_info_button ();
  215. static void cl_cycle_mode_action ();
  216. static void cl_dcache_mode_action ();
  217. static void cl_icache_mode_action ();
  218. static void cl_reinit_prompt_destroyed ();
  219. static void cl_reinit_prompt ();
  220. static void dcache_action ();
  221. static void icache_action ();
  222. static void info_action ();
  223. static void pipe_action ();
  224. #endif
  225.  
  226. #endif
  227.  
  228. /* Local variables: */
  229.  
  230. static Widget breakpointButton;
  231. static void (*confirmAction) () = noop;
  232. static int stack_initialized = 0;
  233. char *xspim_file_name = NULL;    /* Retain last file's name. */
  234.  
  235.  
  236.  
  237. #ifdef __STDC__
  238. void
  239. record_file_name_for_prompt (char *name)
  240. #else
  241. void
  242. record_file_name_for_prompt (name)
  243.      char *name;
  244. #endif
  245. {
  246.   xspim_file_name = str_copy (name);
  247. }
  248.  
  249.  
  250. #ifdef __STDC__
  251. void
  252. create_buttons (Widget parent)
  253. #else
  254. void
  255. create_buttons (parent)
  256.      Widget parent;
  257. #endif
  258. {
  259.   Widget button;
  260.   Widget command;
  261.   Arg args[10];
  262.  
  263.  
  264.   XtSetArg (args[0], XtNlabel, "quit");
  265.   XtSetArg (args[1], XtNwidth, button_width);
  266.   button = XtCreateManagedWidget ("quitbutton", commandWidgetClass, parent,
  267.                   args, TWO);
  268.   XtAddCallback (button, XtNcallback, quit_prompt, NULL);
  269.  
  270.  
  271.   XtSetArg (args[0], XtNlabel, "load");
  272.   XtSetArg (args[1], XtNwidth, button_width);
  273.   command = XtCreateManagedWidget ("loadbutton", commandWidgetClass, parent,
  274.                    args, TWO);
  275.   XtAddCallback (command, XtNcallback, load_prompt, NULL);
  276.  
  277.  
  278.   XtSetArg (args[0], XtNlabel, "run");
  279.   XtSetArg (args[1], XtNwidth, button_width);
  280.   button = XtCreateManagedWidget ("runbutton", commandWidgetClass, parent,
  281.                   args, TWO);
  282.   XtAddCallback (button, XtNcallback, run_prompt, NULL);
  283.  
  284.  
  285.   XtSetArg (args[0], XtNlabel, "step");
  286.   XtSetArg (args[1], XtNwidth, button_width);
  287.   button = XtCreateManagedWidget ("stepbutton", commandWidgetClass, parent,
  288.                   args, TWO);
  289.   XtAddCallback (button, XtNcallback, step_prompt, NULL);
  290.  
  291.  
  292.   add_clear_button (parent);
  293.  
  294.  
  295.   XtSetArg (args[0], XtNlabel, "set value");
  296.   XtSetArg (args[1], XtNwidth, button_width);
  297.   button = XtCreateManagedWidget ("setvaluebutton", commandWidgetClass, parent,
  298.                   args, TWO);
  299.   XtAddCallback (button, XtNcallback, set_value_prompt, NULL);
  300.  
  301.  
  302.   add_print_button (parent);
  303.  
  304.  
  305.   XtSetArg (args[0], XtNlabel, "breakpoints");
  306.   XtSetArg (args[1], XtNwidth, button_width);
  307.   button = XtCreateManagedWidget ("bkptbutton", commandWidgetClass, parent,
  308.                   args, TWO);
  309.   breakpointButton = button;
  310.   XtAddCallback (button, XtNcallback, breakpoint_prompt, NULL);
  311.  
  312.  
  313.   XtSetArg (args[0], XtNlabel, "help");
  314.   XtSetArg (args[1], XtNwidth, button_width);
  315.   button = XtCreateManagedWidget ("helpbutton", commandWidgetClass, parent,
  316.                   args, TWO);
  317.   XtAddCallback (button, XtNcallback, help_action, NULL);
  318.  
  319.  
  320.   add_terminal_button (parent);
  321.  
  322.  
  323.   add_mode_button (parent);
  324.  
  325.  
  326. #ifdef CL_SPIM
  327.   XtSetArg (args[0], XtNlabel, "pipeline");
  328.   XtSetArg (args[1], XtNwidth, button_width);
  329.   button = XtCreateManagedWidget ("pipebutton", commandWidgetClass, parent,
  330.                   args, TWO);
  331.   XtAddCallback (button, XtNcallback, pipe_action, NULL);
  332.  
  333.  
  334.   add_cache_button (parent);
  335.  
  336.  
  337.   add_info_button (parent);
  338. #endif
  339. }
  340.  
  341.  
  342.  
  343. /* *** Quit *** */
  344.  
  345. static Widget quit_popup = NULL;
  346.  
  347. #ifdef __STDC__
  348. static void
  349. quit_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  350. #else
  351. static void
  352. quit_prompt (button, client_data, call_data)
  353.      Widget button;
  354.      XtPointer client_data, call_data;
  355. #endif
  356. {
  357.   Widget parent, dialog;
  358.   Arg args[10];
  359.   Position x, y;
  360.  
  361.   if (quit_popup == NULL)
  362.     {
  363.       parent = XtParent (button);
  364.  
  365.       XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
  366.       XtSetArg (args[0], XtNx, x);
  367.       XtSetArg (args[1], XtNy, y);
  368.       quit_popup = XtCreatePopupShell ("prompt", transientShellWidgetClass,
  369.                        parent, args, TWO);
  370.       XtAddCallback (quit_popup, XtNdestroyCallback, quit_prompt_destroyed,
  371.              (XtPointer) 0);
  372.  
  373.       XtSetArg (args[0], XtNlabel, "quit?");
  374.       dialog = XtCreateManagedWidget ("quit", dialogWidgetClass, quit_popup,
  375.                       args, ONE);
  376.  
  377.       XawDialogAddButton (dialog, "quit", quit_action, (XtPointer) dialog);
  378.       XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
  379.               (XtPointer) dialog);
  380.  
  381.     }
  382.   confirmAction = quit_action;
  383.   XtPopup (quit_popup, XtGrabNone);
  384. }
  385.  
  386.  
  387. #ifdef __STDC__
  388. static void
  389. quit_action (Widget w, XtPointer client_data, XtPointer call_data)
  390. #else
  391. static void
  392. quit_action (w, client_data, call_data)
  393.      Widget w;
  394.      XtPointer client_data, call_data;
  395. #endif
  396. {
  397.   Widget dialog = (Widget) client_data;
  398.  
  399.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  400.   XtDestroyApplicationContext (XtWidgetToApplicationContext (w));
  401.   exit (0);
  402. }
  403.  
  404.  
  405. #ifdef __STDC__
  406. static void
  407. quit_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  408. #else
  409. static void
  410. quit_prompt_destroyed (w, client_data, call_data)
  411.      Widget w;
  412.      XtPointer client_data, call_data;
  413. #endif
  414. {
  415.   quit_popup = NULL;
  416. }
  417.  
  418.  
  419. /* *** Load *** */
  420.  
  421. static Widget load_popup = NULL;
  422.  
  423. #ifdef __STDC__
  424. static void
  425. load_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  426. #else
  427. static void
  428. load_prompt (button, client_data, call_data)
  429.      Widget button;
  430.      XtPointer client_data, call_data;
  431. #endif
  432. {
  433.   Widget parent, dialog;
  434.   Arg args[10];
  435.   Position x, y;
  436.  
  437.   if (load_popup == NULL)
  438.     {
  439.       parent = XtParent (button);
  440.  
  441.       XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
  442.       XtSetArg (args[0], XtNx, x);
  443.       XtSetArg (args[1], XtNy, y);
  444.       load_popup = XtCreatePopupShell ("popup", transientShellWidgetClass,
  445.                       parent, args, TWO);
  446.       XtAddCallback (load_popup, XtNdestroyCallback, load_prompt_destroyed,
  447.              (XtPointer) 0);
  448.  
  449.       if (xspim_file_name == NULL)
  450.     xspim_file_name = str_copy ("");
  451.       XtSetArg (args[0], XtNlabel, "input filename:");
  452.       XtSetArg (args[1], XtNvalue, xspim_file_name);
  453.       dialog = XtCreateManagedWidget ("dialog", dialogWidgetClass, load_popup,
  454.                       args, TWO);
  455.  
  456.       XawDialogAddButton (dialog, "assembly file", read_assm_file_action,
  457.               (XtPointer) dialog);
  458. #ifdef mips
  459.       XawDialogAddButton (dialog, "executable file", read_exec_file_action,
  460.               (XtPointer) dialog);
  461. #endif
  462.       XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
  463.               (XtPointer) dialog);
  464.     }
  465.  
  466.   confirmAction =  read_assm_file_action;
  467.   XtPopup (load_popup, XtGrabNone);
  468. }
  469.  
  470.  
  471. #ifdef __STDC__
  472. static void
  473. read_assm_file_action (Widget w, XtPointer client_data, XtPointer call_data)
  474. #else
  475. static void
  476. read_assm_file_action (w, client_data, call_data)
  477.      Widget w;
  478.      XtPointer client_data, call_data;
  479. #endif
  480. {
  481.   Widget dialog = (Widget) client_data;
  482.   String value = XawDialogGetValueString (dialog);
  483.  
  484.   free (xspim_file_name);
  485.   xspim_file_name = str_copy (value);
  486.   read_file (value, 1);
  487.  
  488.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  489. }
  490.  
  491.  
  492.  
  493. #ifdef mips
  494. #ifdef __STDC__
  495. static void
  496. read_exec_file_action (Widget w, XtPointer client_data, XtPointer call_data)
  497. #else
  498. static void
  499. read_exec_file_action (w, client_data, call_data)
  500.      Widget w;
  501.      XtPointer client_data, call_data;
  502. #endif
  503. {
  504.   Widget dialog = (Widget) client_data;
  505.   String value = XawDialogGetValueString (dialog);
  506.  
  507.   free (xspim_file_name);
  508.   xspim_file_name = str_copy (value);
  509.   read_file (value, 0);
  510.  
  511.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  512. }
  513. #endif
  514.  
  515.  
  516. #ifdef __STDC__
  517. static void
  518. load_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  519. #else
  520. static void
  521. load_prompt_destroyed (w, client_data, call_data)
  522.      Widget w;
  523.      XtPointer client_data, call_data;
  524. #endif
  525. {
  526.   load_popup = NULL;
  527. }
  528.  
  529.  
  530. /* *** Run *** */
  531.  
  532. static Widget run_popup = NULL;
  533. static Widget run_field1_text, run_field2_text;
  534.  
  535. #ifdef __STDC__
  536. static void
  537. run_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  538. #else
  539. static void
  540. run_prompt (button, client_data, call_data)
  541.      Widget button;
  542.      XtPointer client_data, call_data;
  543. #endif
  544. {
  545.   char sa[20];
  546.  
  547.   if (run_popup == NULL)
  548.     {
  549.       sprintf (sa, "0x%08x", starting_address ());
  550.       run_popup = popup_two_field_dialog (button, "run program",
  551.                      "starting address:", sa,
  552.                      "args:", xspim_file_name,
  553.                      "ok", run_program_action,
  554.                      NULL, NULL,
  555.                      &run_field1_text, &run_field2_text);
  556.       XtAddCallback (run_popup, XtNdestroyCallback, run_prompt_destroyed,
  557.              (XtPointer) 0);
  558.     }
  559.   confirmAction =  run_program_action;
  560.   XtPopup (run_popup, XtGrabNone);
  561. }
  562.  
  563.  
  564. #ifdef __STDC__
  565. static void
  566. run_program_action (Widget w, XtPointer client_data, XtPointer call_data)
  567. #else
  568. static void
  569. run_program_action (w, client_data, call_data)
  570.      Widget w;
  571.      XtPointer client_data, call_data;
  572. #endif
  573. {
  574.   Arg args[10];
  575.   String value1, value2;
  576.   Widget form = XtParent (w);
  577.   mem_addr addr;
  578.  
  579.   XtSetArg (args[0], XtNstring, &value1);
  580.   XtGetValues (run_field1_text, args, ONE);
  581.  
  582.   XtSetArg (args[0], XtNstring, &value2);
  583.   XtGetValues (run_field2_text, args, ONE);
  584.  
  585.   destroy_popup_prompt (NULL, (XtPointer) form, NULL);
  586.  
  587. #ifdef CL_SPIM
  588.   if (cycle_level) {
  589.     if (cycle_running)
  590.       kill_prog_fds ();
  591.     cl_initialize_world (1);
  592.   }
  593. #endif
  594.   init_stack (value2);
  595.   addr = strtoul (value1, NULL, 16);
  596.   if (addr > 0)
  597.     start_program (addr);
  598. }
  599.  
  600.  
  601. #ifdef __STDC__
  602. static void
  603. init_stack (char *args)
  604. #else
  605. static void
  606. init_stack (args)
  607.      char *args;
  608. #endif
  609. {
  610.   int argc = 0;
  611.   char *argv[10000];
  612.   char *a;
  613.  
  614.   if (stack_initialized)
  615.     return;
  616.   while (*args != '\0')
  617.     {
  618.       /* Skip leading blanks */
  619.       while (*args == ' ' || *args == '\t') args++;
  620.       /* First non-blank char */
  621.       a = args;
  622.       /* Last non-blank, non-null char */
  623.       while (*args != ' ' && *args != '\t' && *args != '\0') args++;
  624.       /* Terminate word */
  625.       if (a != args)
  626.     {
  627.       if (*args != '\0')
  628.         *args++ = '\0';    /* Null terminate */
  629.       argv [argc++] = a;
  630.     }
  631.     }
  632.   initialize_run_stack (argc, argv);
  633.   stack_initialized = 1;
  634. }
  635.  
  636.  
  637. #ifdef __STDC__
  638. static void
  639. run_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  640. #else
  641. static void
  642. run_prompt_destroyed (w, client_data, call_data)
  643.      Widget w;
  644.      XtPointer client_data, call_data;
  645. #endif
  646. {
  647.   run_popup = NULL;
  648. }
  649.  
  650.  
  651. /* *** Step *** */
  652.  
  653. static char *step_size = NULL;    /* Retain step size */
  654.  
  655. static Widget step_popup = NULL;
  656. static Widget step_field1_text, step_field2_text;
  657.  
  658. #ifdef __STDC__
  659. static void
  660. step_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  661. #else
  662. static void
  663. step_prompt (button, client_data, call_data)
  664.      Widget button;
  665.      XtPointer client_data, call_data;
  666. #endif
  667. {
  668.   if (step_popup == NULL)
  669.     {
  670.       if (step_size == NULL)
  671.     step_size = str_copy ("1");
  672.       step_popup = popup_two_field_dialog (button, "step program",
  673.                       "number of steps:", step_size,
  674.                       "args:", xspim_file_name,
  675.                       "step", step_program_action,
  676.                       "continue", step_continue_action,
  677.                       &step_field1_text,
  678.                       &step_field2_text);
  679.       XtAddCallback (step_popup, XtNdestroyCallback, step_prompt_destroyed,
  680.              (XtPointer) 0);
  681.     }
  682.   confirmAction =  step_program_action;
  683.   XtPopup (step_popup, XtGrabNone);
  684. }
  685.  
  686.  
  687. #ifdef __STDC__
  688. static void
  689. step_program_action (Widget w, XtPointer client_data, XtPointer call_data)
  690. #else
  691. static void
  692. step_program_action (w, client_data, call_data)
  693.      Widget w;
  694.      XtPointer client_data, call_data;
  695. #endif
  696. {
  697.   Arg args[10];
  698.   String value1, value2;
  699.   mem_addr addr;
  700.   int steps;
  701.  
  702.   XtSetArg (args[0], XtNstring, &value1);
  703.   XtGetValues (step_field1_text, args, ONE);
  704.  
  705.   XtSetArg (args[0], XtNstring, &value2);
  706.   XtGetValues (step_field2_text, args, ONE);
  707.  
  708.   steps = atoi (value1);
  709.   free (step_size);
  710.   step_size = str_copy (value1);
  711.   addr = starting_address ();
  712. #ifdef CL_SPIM
  713.   if (!cycle_running && cycle_level) 
  714.     cl_initialize_world (1);
  715. #endif
  716.   init_stack (value2);
  717.   if (steps > 0 && addr > 0)
  718.     execute_program (addr, steps, 1, 1);
  719.   else
  720.     error ("Cannot step %d steps from 0x%x\n", steps, addr);
  721. }
  722.  
  723.  
  724. #ifdef __STDC__
  725. static void
  726. step_continue_action (Widget w, XtPointer client_data, XtPointer call_data)
  727. #else
  728. static void
  729. step_continue_action (w, client_data, call_data)
  730.      Widget w;
  731.      XtPointer client_data, call_data;
  732. #endif
  733. {
  734.   Widget dialog = (Widget) client_data;
  735.  
  736.   XtPopdown (XtParent (dialog));
  737.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  738.   step_popup = NULL;
  739.   execute_program (PC, DEFAULT_RUN_STEPS, 0, 0);
  740. }
  741.  
  742.  
  743. #ifdef __STDC__
  744. static void
  745. step_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  746. #else
  747. static void
  748. step_prompt_destroyed (w, client_data, call_data)
  749.      Widget w;
  750.      XtPointer client_data, call_data;
  751. #endif
  752. {
  753.   step_popup = NULL;
  754. }
  755.  
  756.  
  757. /* *** Clear *** */
  758.  
  759. #ifdef __STDC__
  760. static void
  761. add_clear_button (Widget parent)
  762. #else
  763. static void
  764. add_clear_button (parent)
  765.      Widget parent;
  766. #endif
  767. {
  768.   Widget command, menu, entry;
  769.   Arg args[2];
  770.  
  771.   XtSetArg (args[0], XtNwidth, button_width);
  772.   command = XtCreateManagedWidget ("clear", menuButtonWidgetClass,
  773.                    parent, args, ONE);
  774.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
  775.                  NULL, ZERO);
  776.  
  777.   entry = XtCreateManagedWidget ("registers", smeBSBObjectClass, menu,
  778.                  args, ONE);
  779.   XtAddCallback (entry, XtNcallback, clear_program_state_action,
  780.          (XtPointer) 0);
  781.  
  782.   entry = XtCreateManagedWidget ("memory & registers", smeBSBObjectClass, menu,
  783.                  args, ONE);
  784.   XtAddCallback (entry, XtNcallback, clear_program_state_action,
  785.          (XtPointer) 1);
  786. }
  787.  
  788.  
  789. #ifdef __STDC__
  790. static void
  791. clear_program_state_action (Widget w, XtPointer client_data,
  792.                 XtPointer call_data)
  793. #else
  794. static void
  795. clear_program_state_action (w, client_data, call_data)
  796.      Widget w;
  797.      XtPointer client_data, call_data;
  798. #endif
  799. {
  800.   int clear_world = (int) client_data;
  801.  
  802.   if (clear_world)
  803.     {
  804.       write_output (message_out, "Memory and registers cleared\n\n");
  805.       initialize_world (load_trap_handler && !bare_machine);
  806.       write_startup_message ();
  807.       stack_initialized = 0;
  808. #ifdef CL_SPIM
  809.       cl_initialize_world (0);
  810. #endif
  811.     }
  812.   else
  813.     {
  814.       write_output (message_out, "Registers cleared\n\n");
  815. #ifdef CL_SPIM
  816.       cl_initialize_world (0);
  817. #else
  818.       initialize_registers ();
  819. #endif
  820.     }
  821.   redisplay_text ();
  822.   redisplay_data ();
  823. }
  824.  
  825.  
  826. /* *** Set Value *** */
  827.  
  828. static Widget set_value_popup = NULL;
  829. static Widget set_field1_text, set_field2_text;
  830.  
  831. #ifdef __STDC__
  832. static void
  833. set_value_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  834. #else
  835. static void
  836. set_value_prompt (button, client_data, call_data)
  837.      Widget button;
  838.      XtPointer client_data, call_data;
  839. #endif
  840. {
  841.   if (set_value_popup == NULL)
  842.     {
  843.       set_value_popup = popup_two_field_dialog (button, "set value",
  844.                        "register/location:", "",
  845.                        "value:", "",
  846.                        "set", parse_set_value,
  847.                        NULL, NULL,
  848.                        &set_field1_text, &set_field2_text);
  849.       XtAddCallback (set_value_popup, XtNdestroyCallback,
  850.              set_value_destroyed, (XtPointer) 0);
  851.     }
  852.   confirmAction = parse_set_value;
  853.   XtPopup (set_value_popup, XtGrabNone);
  854. }
  855.  
  856.  
  857. #ifdef __STDC__
  858. static void
  859. parse_set_value (Widget w, XtPointer client_data, XtPointer call_data)
  860. #else
  861. static void
  862. parse_set_value (w, client_data, call_data)
  863.      Widget w;
  864.      XtPointer client_data, call_data;
  865. #endif
  866. {
  867.   Arg args[10];
  868.   String value1, value2;
  869.   Widget form = XtParent (w);
  870.  
  871.   XtSetArg (args[0], XtNstring, &value1);
  872.   XtGetValues (set_field1_text, args, ONE);
  873.  
  874.   XtSetArg (args[0], XtNstring, &value2);
  875.   XtGetValues (set_field2_text, args, ONE);
  876.  
  877.   destroy_popup_prompt (NULL, (XtPointer) form, NULL);
  878.  
  879.   set_value_action (value1, value2);
  880. }
  881.  
  882.  
  883. #ifdef __STDC__
  884. static void
  885. set_value_action (char *location_str, char *value_str)
  886. #else
  887. static void
  888. set_value_action (location_str, value_str)
  889.      char *location_str, *value_str;
  890. #endif
  891. {
  892.   long value;
  893.   int reg_no;
  894.  
  895.   value = strtol (value_str, NULL, 16);
  896.   reg_no = register_name_to_number (location_str);
  897.  
  898.   if (reg_no < 0)
  899.     if (*location_str == '$' || *location_str == 'r' || *location_str == 'R')
  900.       reg_no = register_name_to_number (location_str + 1);
  901.  
  902.   if (reg_no == 0)
  903.     error ("Cannot modify register 0\n");
  904.   else if (reg_no > 0)
  905.     R[reg_no] = value;
  906.   else if (streq (location_str, "Status") || streq (location_str, "status"))
  907.     Status_Reg = value;
  908.   else if (streq (location_str, "PC") || streq (location_str, "pc"))
  909.     PC = value;
  910.   else if (streq (location_str, "EPC") | streq (location_str, "epc"))
  911.     EPC = value;
  912.   else
  913.     {
  914.       char *eptr;
  915.       mem_addr addr;
  916.  
  917.       /* Try to parse string as a number */
  918.       addr = strtol (location_str, &eptr, 16);
  919.       if (eptr == location_str)
  920.     error ("Unknown register selected: %s\n", location_str);
  921.       else
  922.     SET_MEM_WORD (addr, value);
  923.     }
  924.   redisplay_data ();
  925. }
  926.  
  927.  
  928. #ifdef __STDC__
  929. static void
  930. set_value_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  931. #else
  932. static void
  933. set_value_destroyed (w, client_data, call_data)
  934.      Widget w;
  935.      XtPointer client_data, call_data;
  936. #endif
  937. {
  938.   set_value_popup = NULL;
  939. }
  940.  
  941.  
  942. /* *** Print *** */
  943.  
  944. #ifdef __STDC__
  945. static void
  946. add_print_button (Widget parent)
  947. #else
  948. static void
  949. add_print_button (parent)
  950.      Widget parent;
  951. #endif
  952. {
  953.   Widget command, menu, entry;
  954.   Arg args[2];
  955.  
  956.   XtSetArg (args[0], XtNwidth, button_width);
  957.   command = XtCreateManagedWidget ("print", menuButtonWidgetClass,
  958.                    parent, args, ONE);
  959.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
  960.                  NULL, ZERO);
  961.  
  962.   entry = XtCreateManagedWidget ("memory location(s)", smeBSBObjectClass, menu,
  963.                  args, ONE);
  964.   XtAddCallback (entry, XtNcallback, print_mem_prompt, NULL);
  965.  
  966.   entry = XtCreateManagedWidget ("global symbols", smeBSBObjectClass, menu,
  967.                  args, ONE);
  968.   XtAddCallback (entry, XtNcallback, print_symbol_action, NULL);
  969. }
  970.  
  971.  
  972. static Widget print_popup = NULL;
  973. static Widget print_field1_text, print_field2_text;
  974.  
  975. #ifdef __STDC__
  976. static void
  977. print_mem_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  978. #else
  979. static void
  980. print_mem_prompt (button, client_data, call_data)
  981.      Widget button;
  982.      XtPointer client_data, call_data;
  983. #endif
  984. {
  985.   if (print_popup == NULL)
  986.     {
  987.       print_popup = popup_two_field_dialog (XtParent (button), "print memory",
  988.                     "from", "",
  989.                     "to", "",
  990.                     "print", parse_print_value,
  991.                     NULL, NULL,
  992.                     &print_field1_text,
  993.                     &print_field2_text);
  994.       XtAddCallback (print_popup, XtNdestroyCallback, print_prompt_destroyed,
  995.              (XtPointer) 0);
  996.     }
  997.   confirmAction = parse_print_value;
  998.   XtPopup (print_popup, XtGrabNone);
  999. }
  1000.  
  1001.  
  1002. #ifdef __STDC__
  1003. static void
  1004. parse_print_value (Widget w, XtPointer client_data, XtPointer call_data)
  1005. #else
  1006. static void
  1007. parse_print_value (w, client_data, call_data)
  1008.      Widget w;
  1009.      XtPointer client_data, call_data;
  1010. #endif
  1011. {
  1012.   Arg args[10];
  1013.   String value1, value2;
  1014.   Widget form = XtParent (w);
  1015.  
  1016.   XtSetArg (args[0], XtNstring, &value1);
  1017.   XtGetValues (print_field1_text, args, ONE);
  1018.  
  1019.   XtSetArg (args[0], XtNstring, &value2);
  1020.   XtGetValues (print_field2_text, args, ONE);
  1021.  
  1022.   XtPopdown (XtParent (form));
  1023.   destroy_popup_prompt (NULL, (XtPointer) form, NULL);
  1024.  
  1025.   if (!streq (value1, ""))
  1026.     {
  1027.       mem_addr from, to;
  1028.  
  1029.       from = strtoul (value1, NULL, 16);
  1030.       to = strtoul (value2, NULL, 16);
  1031.       if (streq (value2, ""))
  1032.     print_mem (from);
  1033.       else
  1034.     for ( ; from <= to; from+= BYTES_PER_WORD)
  1035.       print_mem (from);
  1036.     }
  1037. }
  1038.  
  1039.  
  1040. #ifdef __STDC__
  1041. static void
  1042. print_symbol_action (Widget w, XtPointer client_data, XtPointer call_data)
  1043. #else
  1044. static void
  1045. print_symbol_action (w, client_data, call_data)
  1046.      Widget w;
  1047.      XtPointer client_data, call_data;
  1048. #endif
  1049. {
  1050.   print_symbols ();
  1051. }
  1052.  
  1053.  
  1054. #ifdef __STDC__
  1055. static void
  1056. print_prompt_destroyed (Widget w, XtPointer client_data, XtPointer call_data)
  1057. #else
  1058. static void
  1059. print_prompt_destroyed (w, client_data, call_data)
  1060.      Widget w;
  1061.      XtPointer client_data, call_data;
  1062. #endif
  1063. {
  1064.   print_popup = NULL;
  1065. }
  1066.  
  1067.  
  1068. /* *** Breakpoints **** */
  1069.  
  1070. static char *breakpoint_addr = NULL; /* Retain last breakpoint address */
  1071.  
  1072. static Widget bkpt_popup = NULL;
  1073.  
  1074. #ifdef __STDC__
  1075. static void
  1076. breakpoint_prompt (Widget button, XtPointer client_data, XtPointer call_data)
  1077. #else
  1078. static void
  1079. breakpoint_prompt (button, client_data, call_data)
  1080.      Widget button;
  1081.      XtPointer client_data, call_data;
  1082. #endif
  1083. {
  1084.   Widget parent, dialog;
  1085.   Arg args[10];
  1086.   Position x, y;
  1087.  
  1088.   if (bkpt_popup == NULL)
  1089.     {
  1090.       parent = XtParent (button);
  1091.  
  1092.       XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
  1093.       XtSetArg (args[0], XtNx, x);
  1094.       XtSetArg (args[1], XtNy, y);
  1095.       bkpt_popup = XtCreatePopupShell ("popup", transientShellWidgetClass,
  1096.                       parent, args, TWO);
  1097.  
  1098.       if (breakpoint_addr == NULL)
  1099.     breakpoint_addr = str_copy ("");
  1100.       XtSetArg (args[0], XtNlabel, "address:");
  1101.       XtSetArg (args[1], XtNvalue, breakpoint_addr);
  1102.       dialog = XtCreateManagedWidget ("dialog", dialogWidgetClass,
  1103.                       bkpt_popup,
  1104.                       args, TWO);
  1105.       XtAddCallback (bkpt_popup, XtNdestroyCallback,
  1106.              breakpoint_prompt_destroyed, (XtPointer) 0);
  1107.  
  1108.       XawDialogAddButton (dialog, "add",
  1109.               add_breakpoint_action, (XtPointer) dialog);
  1110.       XawDialogAddButton (dialog, "delete",
  1111.               delete_breakpoint_action, (XtPointer) dialog);
  1112.       XawDialogAddButton (dialog, "list",
  1113.               list_breakpoint_action, (XtPointer) dialog);
  1114.       XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
  1115.               (XtPointer) dialog);
  1116.     }
  1117.  
  1118.   confirmAction = add_breakpoint_action;
  1119.   XtPopup (bkpt_popup, XtGrabNone);
  1120. }
  1121.  
  1122.  
  1123. #ifdef __STDC__
  1124. static void
  1125. add_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
  1126. #else
  1127. static void
  1128. add_breakpoint_action (w, client_data, call_data)
  1129.      Widget w;
  1130.      XtPointer client_data, call_data;
  1131. #endif
  1132. {
  1133.   Widget dialog = (Widget) client_data;
  1134.   String value = XawDialogGetValueString (dialog);
  1135.   mem_addr addr;
  1136.  
  1137.   free (breakpoint_addr);
  1138.   breakpoint_addr = str_copy (value);
  1139.  
  1140.   while (*breakpoint_addr == ' ') breakpoint_addr++;
  1141.   if (isdigit (*breakpoint_addr))
  1142.     addr = strtoul (value, NULL, 16);
  1143.   else
  1144.     addr = find_symbol_address (breakpoint_addr);
  1145.  
  1146.   add_breakpoint (addr);
  1147.  
  1148.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  1149. }
  1150.  
  1151.  
  1152. #ifdef __STDC__
  1153. static void
  1154. delete_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
  1155. #else
  1156. static void
  1157. delete_breakpoint_action (w, client_data, call_data)
  1158.      Widget w;
  1159.      XtPointer client_data, call_data;
  1160. #endif
  1161. {
  1162.   Widget dialog = (Widget) client_data;
  1163.   String value = XawDialogGetValueString (dialog);
  1164.   mem_addr addr;
  1165.  
  1166.   free (breakpoint_addr);
  1167.   breakpoint_addr = str_copy (value);
  1168.   addr = strtoul (value, NULL, 16);
  1169.  
  1170.   delete_breakpoint (addr);
  1171.  
  1172.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  1173. }
  1174.  
  1175.  
  1176. #ifdef __STDC__
  1177. static void
  1178. list_breakpoint_action (Widget w, XtPointer client_data, XtPointer call_data)
  1179. #else
  1180. static void
  1181. list_breakpoint_action (w, client_data, call_data)
  1182.      Widget w;
  1183.      XtPointer client_data, call_data;
  1184. #endif
  1185. {
  1186.   list_breakpoints ();
  1187. }
  1188.  
  1189.  
  1190. #ifdef __STDC__
  1191. static void
  1192. breakpoint_prompt_destroyed (Widget w, XtPointer client_data,
  1193.                  XtPointer call_data)
  1194. #else
  1195. static void
  1196. breakpoint_prompt_destroyed (w, client_data, call_data)
  1197.      Widget w;
  1198.      XtPointer client_data, call_data;
  1199. #endif
  1200. {
  1201.   bkpt_popup = NULL;
  1202. }
  1203.  
  1204.  
  1205. /* *** Help *** */
  1206.  
  1207. #ifdef __STDC__
  1208. static void
  1209. help_action (Widget w, XtPointer ignore, XtPointer ignored)
  1210. #else
  1211. static void
  1212. help_action (w, ignore, ignored)
  1213.      Widget w;
  1214.      XtPointer ignore;
  1215.      XtPointer ignored;
  1216. #endif
  1217. {
  1218.   static char * msg = "\nSPIM is a MIPS R2000 simulator.\n\
  1219. Copyright (C) 1990-1994 by James R. Larus, larus@cs.wisc.edu\n\n\
  1220. quit  -- Exit from the simulator\n\
  1221. load -- Read a file into memory\n\
  1222. run -- Execute a program\n\
  1223. step -- Single-step through a program\n\
  1224. clear -- Reinitialize registers or memory\n\
  1225. set value -- Set the value in register or memory\n\
  1226. print -- Print the value in register or memory\n\
  1227. breakpoint -- Set or delete a breakpoint\n\
  1228. help -- This message\n\
  1229. terminal -- Raise or hide console window\n\
  1230. mode -- Set SPIM operating modes\n";
  1231.  
  1232.   write_output (message_out, msg);
  1233. }
  1234.  
  1235.  
  1236. /* *** Terminal *** */
  1237.  
  1238. #ifdef __STDC__
  1239. static void
  1240. add_terminal_button (Widget parent)
  1241. #else
  1242. static void
  1243. add_terminal_button (parent)
  1244.      Widget parent;
  1245. #endif
  1246. {
  1247.   Widget command, menu, entry;
  1248.   Arg args[2];
  1249.  
  1250.   XtSetArg (args[0], XtNwidth, button_width);
  1251.   command = XtCreateManagedWidget ("terminal", menuButtonWidgetClass,
  1252.                    parent, args, ONE);
  1253.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
  1254.                  NULL, ZERO);
  1255.  
  1256.   entry = XtCreateManagedWidget ("popup console", smeBSBObjectClass, menu,
  1257.                  args, ONE);
  1258.   XtAddCallback (entry, XtNcallback, popup_console, NULL);
  1259. }
  1260.  
  1261.  
  1262. /* *** Mode *** */
  1263.  
  1264. static Widget modeCommand;
  1265. #ifdef CL_SPIM
  1266. static Widget bareflag, quietflag, modeChoice;
  1267. static Widget cl_reinitPopup = NULL;
  1268. #endif
  1269.  
  1270. #ifdef __STDC__
  1271. static void
  1272. add_mode_button (Widget parent)
  1273. #else
  1274. static void
  1275. add_mode_button (parent)
  1276.      Widget parent;
  1277. #endif
  1278. {
  1279.   Widget menu, entry;
  1280.   Arg args[2];
  1281.  
  1282.   XtSetArg (args[0], XtNwidth, button_width);
  1283.   modeCommand = XtCreateManagedWidget ("mode", menuButtonWidgetClass,
  1284.                        parent, args, ONE);
  1285.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, modeCommand,
  1286.                  NULL, ZERO);
  1287.  
  1288.   XtSetArg (args[0], XtNleftMargin, 20);
  1289.   entry = XtCreateManagedWidget ("bare", smeBSBObjectClass, menu, args, ONE);
  1290.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1291.   if (bare_machine)
  1292.     {
  1293.       XtSetArg (args[0], XtNleftBitmap, mark);
  1294.       XtSetValues (entry, args, ONE);
  1295.     }
  1296. #ifdef CL_SPIM
  1297.   bareflag = entry;
  1298. #endif
  1299.  
  1300.   XtSetArg (args[0], XtNleftMargin, 20);
  1301.   entry = XtCreateManagedWidget ("quiet", smeBSBObjectClass, menu, args, ONE);
  1302.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1303.   if (quiet)
  1304.     {
  1305.       XtSetArg (args[0], XtNleftBitmap, mark);
  1306.       XtSetValues (entry, args, ONE);
  1307.     }
  1308. #ifdef CL_SPIM
  1309.   quietflag = entry;
  1310.  
  1311.   XtSetArg (args[0], XtNleftMargin, 20);
  1312.   entry = XtCreateManagedWidget ("cycle", smeBSBObjectClass, menu, args, ONE);
  1313.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1314.   if (cycle_level)
  1315.     {
  1316.       XtSetArg (args[0], XtNleftBitmap, mark);
  1317.       XtSetValues (entry, args, ONE);
  1318.     }
  1319.  
  1320.   XtSetArg (args[0], XtNleftMargin, 20);
  1321.   entry = XtCreateManagedWidget ("tlb", smeBSBObjectClass, menu, args, ONE);
  1322.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1323.   if (tlb_on)
  1324.     {
  1325.       XtSetArg (args[0], XtNleftBitmap, mark);
  1326.       XtSetValues (entry, args, ONE);
  1327.     }
  1328.  
  1329.   XtSetArg (args[0], XtNleftMargin, 20);
  1330.   entry = XtCreateManagedWidget ("icache", smeBSBObjectClass, menu, args, ONE);
  1331.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1332.   if (icache_on)
  1333.     {
  1334.       XtSetArg (args[0], XtNleftBitmap, mark);
  1335.       XtSetValues (entry, args, ONE);
  1336.     }
  1337.  
  1338.   XtSetArg (args[0], XtNleftMargin, 20);
  1339.   entry = XtCreateManagedWidget ("dcache", smeBSBObjectClass, menu, args, ONE);
  1340.   XtAddCallback (entry, XtNcallback, select_mode_action, NULL);
  1341.   if (dcache_on)
  1342.     {
  1343.       XtSetArg (args[0], XtNleftBitmap, mark);
  1344.       XtSetValues (entry, args, ONE);
  1345.     }
  1346. #endif
  1347. }
  1348.  
  1349.  
  1350. #ifdef __STDC__
  1351. static void
  1352. select_mode_action (Widget w, XtPointer client_data, XtPointer call_data)
  1353. #else
  1354. static void
  1355. select_mode_action (w, client_data, call_data)
  1356.      Widget w;
  1357.      XtPointer client_data, call_data;
  1358. #endif
  1359. {
  1360.   Arg args[10];
  1361.   String name = XtName (w);
  1362.  
  1363. #ifdef CL_SPIM
  1364.   modeChoice = w;
  1365. #endif
  1366.  
  1367.   if (streq (name, "bare"))
  1368.     {
  1369.       bare_machine = !bare_machine;
  1370.       if (bare_machine)
  1371.     XtSetArg (args[0], XtNleftBitmap, mark);
  1372.       else
  1373.     XtSetArg (args[0], XtNleftBitmap, None);
  1374.       XtSetValues (w, args, ONE);
  1375.     }
  1376.   else if (streq (name, "quiet"))
  1377.     {
  1378.       quiet = !quiet;
  1379.       if (quiet)
  1380.     XtSetArg (args[0], XtNleftBitmap, mark);
  1381.       else
  1382.     XtSetArg (args[0], XtNleftBitmap, None);
  1383.       XtSetValues (w, args, ONE);
  1384.     }
  1385. #ifdef CL_SPIM
  1386.   else if (streq (name, "cycle"))
  1387.     cl_reinit_prompt ("Changing cycle mode will reinitialize everything",
  1388.              cl_cycle_mode_action);
  1389.   else if (streq (name, "tlb"))
  1390.     {
  1391.       if (cycle_running && (icache_on || dcache_on))
  1392.     write_output (message_out,
  1393.               "Toggling TLB invalidates cache values.\nReinitialize, then set TLB.\n");
  1394.       else
  1395.     {
  1396.       if (tlb_on)
  1397.         {
  1398.           tlb_on = 0;
  1399.           XtSetArg (args[0], XtNleftBitmap, None);
  1400.         }
  1401.       else
  1402.         {
  1403.           tlb_on = 1;
  1404.           XtSetArg (args[0], XtNleftBitmap, mark);
  1405.           tlb_init ();
  1406.         }
  1407.       XtSetValues (w, args, ONE);
  1408.     }
  1409.     }
  1410.   else if (streq (name, "icache"))
  1411.     {
  1412.       if (cycle_running)
  1413.     cl_reinit_prompt ("Changing cache will invalidate it",
  1414.              cl_icache_mode_action);
  1415.       else
  1416.     {
  1417.       if (icache_on)
  1418.         {
  1419.           icache_on = 0;
  1420.           XtSetArg (args[0], XtNleftBitmap, None);
  1421.         }
  1422.       else
  1423.         {
  1424.           icache_on = 1;
  1425.           XtSetArg (args[0], XtNleftBitmap, mark);
  1426.           cache_init (mem_system, INST_CACHE);
  1427.         }
  1428.       XtSetValues (w, args, ONE);
  1429.     }
  1430.     }
  1431.   else if (streq (name, "dcache"))
  1432.     {
  1433.       if (cycle_running)
  1434.     cl_reinit_prompt ("Changing cache will invalidate it",
  1435.              cl_dcache_mode_action);
  1436.       else
  1437.     {
  1438.       if (dcache_on)
  1439.         {
  1440.           dcache_on = 0;
  1441.           XtSetArg (args[0], XtNleftBitmap, None);
  1442.         }
  1443.       else
  1444.         {
  1445.           dcache_on = 1;
  1446.           XtSetArg (args[0], XtNleftBitmap, mark);
  1447.           cache_init (mem_system, DATA_CACHE);
  1448.         }
  1449.       XtSetValues (w, args, ONE);
  1450.     }
  1451.     }
  1452. #endif
  1453. }
  1454.  
  1455.  
  1456. #ifdef CL_SPIM
  1457. #ifdef __STDC__
  1458. static void
  1459. cl_cycle_mode_action (Widget choice, XtPointer client_data,
  1460.               XtPointer call_data)
  1461. #else
  1462. static void
  1463. cl_cycle_mode_action (choice, client_data, call_data)
  1464.   Widget choice;
  1465.   XtPointer client_data, call_data;
  1466. #endif
  1467. {
  1468.   Arg args[1];
  1469.   String response = XtName (choice);
  1470.  
  1471.   if (streq (response, "continue")) {
  1472.     if (cycle_level) {
  1473.       cycle_level = 0;
  1474.       cl_initialize_world (0);
  1475.       XtSetArg (args[0], XtNleftBitmap, None);
  1476.     }
  1477.     else {
  1478.       cycle_level = 1;
  1479.       bare_machine = 1;
  1480.       quiet = 1;
  1481.       cl_initialize_world (0);
  1482.       XtSetArg (args[0], XtNleftBitmap, mark);
  1483.       XtSetValues (bareflag, args, ONE);
  1484.       XtSetValues (quietflag, args, ONE);
  1485.     }
  1486.     XtSetValues (client_data, args, ONE);
  1487.   }
  1488.   confirmAction = noop;
  1489.   XtDestroyWidget (XtParent(XtParent(choice)));
  1490. }
  1491.  
  1492.  
  1493. #ifdef __STDC__
  1494. static void
  1495. cl_icache_mode_action (Widget choice, XtPointer client_data,
  1496.                XtPointer call_data)
  1497. #else
  1498. static void
  1499. cl_icache_mode_action (choice, client_data, call_data)
  1500.   Widget choice;
  1501.   XtPointer client_data, call_data;
  1502. #endif
  1503. {
  1504.   Arg args[1];
  1505.   String response = XtName (choice);
  1506.  
  1507.   if (streq (response, "continue")) {
  1508.     if (icache_on) {
  1509.       icache_on = 0;
  1510.       XtSetArg (args[0], XtNleftBitmap, None);
  1511.     }
  1512.     else {
  1513.       icache_on = 1;
  1514.       cache_init (mem_system, INST_CACHE);
  1515.       XtSetArg (args[0], XtNleftBitmap, mark);
  1516.     }
  1517.     XtSetValues (client_data, args, ONE);
  1518.   }
  1519.   confirmAction = noop;
  1520.   XtDestroyWidget (XtParent(XtParent(choice)));
  1521. }
  1522.  
  1523.  
  1524. #ifdef __STDC__
  1525. static void
  1526. cl_dcache_mode_action (Widget choice, XtPointer client_data,
  1527.                XtPointer call_data)
  1528. #else
  1529. static void
  1530. cl_dcache_mode_action (choice, client_data, call_data)
  1531.   Widget choice;
  1532.   XtPointer client_data, call_data;
  1533. #endif
  1534. {
  1535.   Arg args[1];
  1536.   String response = XtName (choice);
  1537.  
  1538.   if (streq (response, "continue")) {
  1539.     if (dcache_on) {
  1540.       dcache_on = 0;
  1541.       XtSetArg (args[0], XtNleftBitmap, None);
  1542.     }
  1543.     else {
  1544.       dcache_on = 1;
  1545.       cache_init (mem_system, DATA_CACHE);
  1546.       XtSetArg (args[0], XtNleftBitmap, mark);
  1547.     }
  1548.     XtSetValues (client_data, args, ONE);
  1549.   }
  1550.   confirmAction = noop;
  1551.   XtDestroyWidget (XtParent(XtParent(choice)));
  1552. }
  1553.  
  1554.  
  1555. #ifdef __STDC__
  1556. static void
  1557. cl_reinit_prompt (char *str, void (*callback)())
  1558. #else
  1559. static void
  1560. cl_reinit_prompt (str, callback)
  1561.   char *str;
  1562.   void (*callback)();
  1563. #endif
  1564. {
  1565.   Widget parent, dialog;
  1566.   Arg args[10];
  1567.   Position x, y;
  1568.  
  1569.   if (cl_reinitPopup == NULL)
  1570.     {
  1571.       parent = modeCommand;
  1572.  
  1573.       XtTranslateCoords (XtParent(modeChoice), (Position) 0, (Position) 0,
  1574.              &x, &y);
  1575.       XtSetArg (args[0], XtNx, x);
  1576.       XtSetArg (args[1], XtNy, y);
  1577.       cl_reinitPopup = XtCreatePopupShell ("prompt", transientShellWidgetClass,
  1578.                        parent, args, TWO);
  1579.       XtAddCallback (cl_reinitPopup, XtNdestroyCallback,
  1580.              cl_reinit_prompt_destroyed, (XtPointer) 0);
  1581.  
  1582.       XtSetArg (args[0], XtNlabel, str);
  1583.       dialog = XtCreateManagedWidget ("reinit", dialogWidgetClass,
  1584.                       cl_reinitPopup, args, ONE);
  1585.  
  1586.       XawDialogAddButton (dialog,"continue", callback, (XtPointer)modeChoice);
  1587.       XawDialogAddButton (dialog,"abort command",callback,
  1588.               (XtPointer)modeChoice);
  1589.     }
  1590.   confirmAction = callback;
  1591.   XtPopup (cl_reinitPopup, XtGrabNone);
  1592. }
  1593.  
  1594.  
  1595. #ifdef __STDC__
  1596. static void
  1597. cl_reinit_prompt_destroyed (Widget w, XtPointer client_data,
  1598.                 XtPointer call_data)
  1599. #else
  1600. static void
  1601. cl_reinit_prompt_destroyed (w, client_data, call_data)
  1602.   Widget w;
  1603.   XtPointer client_data, call_data;
  1604. #endif
  1605. {
  1606.   cl_reinitPopup = NULL;
  1607. }
  1608.  
  1609.  
  1610. /* *** Pipeline *** */
  1611.  
  1612. #ifdef __STDC__
  1613. static void
  1614. pipe_action (Widget button, XtPointer client_data, XtPointer call_data)
  1615. #else
  1616. static void
  1617. pipe_action (button, client_data, call_data)
  1618.      Widget button;
  1619.      XtPointer client_data, call_data;
  1620. #endif
  1621. {
  1622.   if (!cycle_level)
  1623.     write_output (message_out, "Cannot view pipeline -- not in cycle level simulation.\n");
  1624.   else popup_pipeline (button, client_data, call_data);
  1625. }
  1626.  
  1627.  
  1628. /* *** Cache *** */
  1629.  
  1630. #ifdef __STDC__
  1631. static void
  1632. add_cache_button (Widget parent)
  1633. #else
  1634. static void
  1635. add_cache_button (parent)
  1636.   Widget parent;
  1637. #endif
  1638. {
  1639.   Widget command, menu, entry;
  1640.   Arg args[2];
  1641.  
  1642.   XtSetArg (args[0], XtNwidth, button_width);
  1643.   command = XtCreateManagedWidget ("cache", menuButtonWidgetClass,
  1644.                    parent, args, ONE);
  1645.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, command,
  1646.                  NULL, ZERO);
  1647.  
  1648.   XtSetArg (args[0], XtNleftMargin, 20);
  1649.   entry = XtCreateManagedWidget ("data", smeBSBObjectClass, menu, args, ONE);
  1650.   XtAddCallback (entry, XtNcallback, dcache_action, NULL);
  1651.  
  1652.   XtSetArg (args[0], XtNleftMargin, 20);
  1653.   entry = XtCreateManagedWidget ("inst", smeBSBObjectClass, menu, args, ONE);
  1654.   XtAddCallback (entry, XtNcallback, icache_action, NULL);
  1655. }
  1656.  
  1657.  
  1658. #ifdef __STDC__
  1659. static void
  1660. dcache_action (Widget button, XtPointer client_data, XtPointer call_data)
  1661. #else
  1662. static void
  1663. dcache_action (button, client_data, call_data)
  1664.      Widget button;
  1665.      XtPointer client_data, call_data;
  1666. #endif
  1667. {
  1668.   if (!cycle_level)
  1669.     write_output (message_out, "Cannot view data cache -- not in cycle level simulation.\n");
  1670.   else if (!dcache_on)
  1671.     write_output (message_out, "Data cache not on.\n");
  1672.   else pop_dcache (button, client_data, call_data);
  1673. }
  1674.  
  1675.  
  1676. #ifdef __STDC__
  1677. static void
  1678. icache_action (Widget button, XtPointer client_data, XtPointer call_data)
  1679. #else
  1680. static void
  1681. icache_action (button, client_data, call_data)
  1682.      Widget button;
  1683.      XtPointer client_data, call_data;
  1684. #endif
  1685. {
  1686.   if (!cycle_level)
  1687.     write_output (message_out, "Cannot view intruction cache -- not in cycle level simulation.\n");
  1688.   else if (!icache_on)
  1689.     write_output (message_out, "Instruction cache not on.\n");
  1690.   else pop_icache (button, client_data, call_data);
  1691. }
  1692.  
  1693.  
  1694. /* *** Info *** */
  1695.  
  1696. #ifdef __STDC__
  1697. static void
  1698. add_info_button (Widget parent)
  1699. #else
  1700. static void
  1701. add_info_button (parent)
  1702.   Widget parent;
  1703. #endif
  1704. {
  1705.   Widget infoCommand, menu, entry;
  1706.   Arg args[2];
  1707.  
  1708.   XtSetArg (args[0], XtNwidth, button_width);
  1709.   infoCommand = XtCreateManagedWidget ("info", menuButtonWidgetClass,
  1710.                        parent, args, ONE);
  1711.   menu = XtCreatePopupShell ("menu", simpleMenuWidgetClass, infoCommand,
  1712.                  NULL, ZERO);
  1713.  
  1714.   XtSetArg (args[0], XtNleftMargin, 20);
  1715.  
  1716.   entry = XtCreateManagedWidget("exceptions",smeBSBObjectClass,menu,args,ONE);
  1717.   XtAddCallback (entry, XtNcallback, info_action, NULL);
  1718.  
  1719.   entry = XtCreateManagedWidget("signals",smeBSBObjectClass, menu, args,ONE);
  1720.   XtAddCallback (entry, XtNcallback, info_action, NULL);
  1721.  
  1722.   entry = XtCreateManagedWidget ("syscalls",smeBSBObjectClass,menu, args,ONE);
  1723.   XtAddCallback (entry, XtNcallback, info_action, NULL);
  1724. }
  1725.  
  1726.  
  1727. #ifdef __STDC__
  1728. static void
  1729. info_action (Widget w, XtPointer client_data, XtPointer call_data)
  1730. #else
  1731. static void
  1732. info_action (w, client_data, call_data)
  1733.   Widget w;
  1734.   XtPointer client_data, call_data;
  1735. #endif
  1736. {
  1737.   String name = XtName(w);
  1738.  
  1739.   if (streq (name, "exceptions"))
  1740.     print_except_stats ();
  1741.   else if (streq (name, "signals"))
  1742.     print_signal_status (ALL_SIGNALS);
  1743.   else if (streq (name, "syscalls"))
  1744.     print_syscall_usage ();
  1745. }
  1746. #endif
  1747.  
  1748.  
  1749. /* *** Continue *** */
  1750.  
  1751. static Widget continue_popup = NULL;
  1752.  
  1753. #ifdef __STDC__
  1754. void
  1755. continue_prompt (int interrupt_seen)
  1756. #else
  1757. void
  1758. continue_prompt (interrupt_seen)
  1759.      int interrupt_seen;
  1760. #endif
  1761. {
  1762.   Widget dialog;
  1763.   Arg args[10];
  1764.   Position x, y;
  1765.   char msg[256];
  1766.  
  1767.   if (continue_popup != NULL)
  1768.     XtDestroyWidget (continue_popup);
  1769.   XtTranslateCoords (breakpointButton, (Position) 0, (Position) 0, &x, &y);
  1770.   XtSetArg (args[0], XtNx, x);
  1771.   XtSetArg (args[1], XtNy, y);
  1772.   continue_popup = XtCreatePopupShell ("prompt", transientShellWidgetClass,
  1773.                       breakpointButton, args, TWO);
  1774.   XtAddCallback (continue_popup, XtNdestroyCallback,
  1775.          continue_prompt_destroyed, (XtPointer) 0);
  1776.  
  1777.   if (interrupt_seen)
  1778.     sprintf (msg, "execution interrupt at 0x%08x", PC);
  1779.   else
  1780.     sprintf (msg, "breakpoint encountered at 0x%08x", PC);
  1781.   XtSetArg (args[0], XtNlabel, msg);
  1782.   dialog = XtCreateManagedWidget ("continue", dialogWidgetClass,
  1783.                   continue_popup, args, ONE);
  1784.  
  1785.   XawDialogAddButton (dialog, "continue", continue_action,
  1786.               (XtPointer) dialog);
  1787.   XawDialogAddButton (dialog, "abort command", destroy_popup_prompt,
  1788.               (XtPointer) dialog);
  1789.  
  1790.   confirmAction = continue_action;
  1791.   XtPopup (continue_popup, XtGrabNone);
  1792. }
  1793.  
  1794.  
  1795. #ifdef __STDC__
  1796. static void
  1797. continue_action (Widget w, XtPointer client_data, XtPointer call_data)
  1798. #else
  1799. static void
  1800. continue_action (w, client_data, call_data)
  1801.      Widget w;
  1802.      XtPointer client_data, call_data;
  1803. #endif
  1804. {
  1805.   Widget dialog = (Widget) client_data;
  1806.  
  1807.   XtPopdown (XtParent (dialog));
  1808.   destroy_popup_prompt (NULL, (XtPointer) dialog, (XtPointer) NULL);
  1809.   continue_popup = NULL;
  1810.   execute_program (PC, 1, 0, 1); /* Step over breakpoint */
  1811.   execute_program (PC, DEFAULT_RUN_STEPS - 1, 0, 0);
  1812. }
  1813.  
  1814.  
  1815. #ifdef __STDC__
  1816. static void
  1817. continue_prompt_destroyed (Widget w, XtPointer client_data,
  1818.                XtPointer call_data)
  1819. #else
  1820. static void
  1821. continue_prompt_destroyed (w, client_data, call_data)
  1822.      Widget w;
  1823.      XtPointer client_data, call_data;
  1824. #endif
  1825. {
  1826.   continue_popup = NULL;
  1827. }
  1828.  
  1829.  
  1830.  
  1831.  
  1832. #ifdef __STDC__
  1833. void
  1834. confirm (Widget widget, XEvent *event, String *params, Cardinal *num_params)
  1835. #else
  1836. void
  1837. confirm (widget, event, params, num_params)
  1838.      Widget widget;
  1839.      XEvent *event;
  1840.      String *params;
  1841.      Cardinal *num_params;
  1842. #endif
  1843. {
  1844.   Widget dialog = XtParent (widget);
  1845.   (*confirmAction) (widget, (XtPointer) dialog, (XtPointer) NULL);
  1846. }
  1847.  
  1848.  
  1849. #ifdef __STDC__
  1850. static void
  1851. destroy_popup_prompt (Widget w, XtPointer client_data, XtPointer call_data)
  1852. #else
  1853. static void
  1854. destroy_popup_prompt (w, client_data, call_data)
  1855.      Widget w;
  1856.      XtPointer client_data, call_data;
  1857. #endif
  1858. {
  1859.   Widget popup = XtParent ((Widget) client_data);
  1860.  
  1861.   confirmAction = noop;
  1862.   XtDestroyWidget (popup);
  1863. }
  1864.  
  1865.  
  1866. #ifdef __STDC__
  1867. static void
  1868. noop (void)
  1869. #else
  1870. static void
  1871. noop ()
  1872. #endif
  1873. {
  1874. }
  1875.  
  1876.  
  1877. #ifdef __STDC__
  1878. static Widget
  1879. popup_two_field_dialog (Widget button, String name, String field1_label,
  1880.             String field1_value, String field2_label,
  1881.             String field2_value, String action_name,
  1882.             void (*action) (/* ??? */), String action2_name,
  1883.             void (*action2) (/* ??? */), Widget *field1_text,
  1884.             Widget *field2_text)
  1885. #else
  1886. static Widget
  1887. popup_two_field_dialog (button, name, field1_label, field1_value,
  1888.              field2_label, field2_value, action_name, action,
  1889.              action2_name, action2, field1_text, field2_text)
  1890.      Widget button;
  1891.      String name, field1_label, field1_value, field2_label, field2_value,
  1892.        action_name, action2_name;
  1893.      void (*action) (), (*action2) ();
  1894.      Widget *field1_text, *field2_text;
  1895. #endif
  1896. {
  1897.   Widget popup, form;
  1898.   Widget labelx, field1, field2;
  1899.   Widget button1, button2, cancelbutton;
  1900.   Widget parent = XtParent (button);
  1901.   Arg args[10];
  1902.   Position x, y;
  1903.   static XtActionsRec action_table []
  1904.     = {{"warp_to_second_dialog", warp_to_second_dialog},};
  1905.  
  1906.   XtTranslateCoords (button, (Position) 0, (Position) 0, &x, &y);
  1907.  
  1908.   XtSetArg (args[0], XtNx, x);
  1909.   XtSetArg (args[1], XtNy, y);
  1910.   popup = XtCreatePopupShell ("prompt", transientShellWidgetClass, parent,
  1911.                   args, TWO);
  1912.  
  1913.   form = XtCreateManagedWidget ("form", formWidgetClass, popup, NULL, ZERO);
  1914.  
  1915.   XtSetArg (args[0], XtNlabel, name);
  1916.   XtSetArg (args[1], XtNborderWidth, 0);
  1917.   labelx = XtCreateManagedWidget ("label", labelWidgetClass, form, args, TWO);
  1918.  
  1919.   XtSetArg (args[0], XtNfromVert, labelx);
  1920.   XtSetArg (args[1], XtNborderWidth, 0);
  1921.   XtSetArg (args[2], XtNlabel, field1_label);
  1922.   field1 = XtCreateManagedWidget ("field1", labelWidgetClass, form, args,
  1923.                   THREE);
  1924.  
  1925.   XtSetArg (args[0], XtNfromHoriz, field1);
  1926.   XtSetArg (args[1], XtNfromVert, labelx);
  1927.   XtSetArg (args[2], XtNeditType, "edit");
  1928.   XtSetArg (args[3], XtNstring, field1_value);
  1929.   XtSetArg (args[4], XtNtype, XawAsciiString);
  1930.   *field1_text = XtCreateManagedWidget ("field1_text", asciiTextWidgetClass,
  1931.                     form, args, FIVE);
  1932.   XtOverrideTranslations (*field1_text,
  1933.               XtParseTranslationTable
  1934.               ("#override \n <Key>Return:warp_to_second_dialog()"));
  1935.   XtAppAddActions (app_context, action_table, XtNumber (action_table));
  1936.  
  1937.   XtSetArg (args[0], XtNfromVert, *field1_text);
  1938.   XtSetArg (args[1], XtNborderWidth, 0);
  1939.   XtSetArg (args[2], XtNlabel, field2_label);
  1940.   field2 = XtCreateManagedWidget ("field2", labelWidgetClass, form, args,
  1941.                   THREE);
  1942.  
  1943.   XtSetArg (args[0], XtNfromHoriz, field1);
  1944.   XtSetArg (args[1], XtNfromVert, *field1_text);
  1945.   XtSetArg (args[2], XtNeditType, "edit");
  1946.   XtSetArg (args[3], XtNstring, field2_value);
  1947.   XtSetArg (args[4], XtNtype, XawAsciiString);
  1948.   *field2_text = XtCreateManagedWidget ("field2_text", asciiTextWidgetClass,
  1949.                     form, args, FIVE);
  1950.   XtOverrideTranslations (*field2_text,
  1951.               XtParseTranslationTable
  1952.               ("#override \n <Key>Return: confirm()"));
  1953.  
  1954.   XtSetArg (args[0], XtNfromVert, *field2_text);
  1955.   button1 = XtCreateManagedWidget (action_name, commandWidgetClass, form,
  1956.                    args, ONE);
  1957.   XtAddCallback (button1, XtNcallback, action, (XtPointer) form);
  1958.  
  1959.   if (action2 != NULL)
  1960.     {
  1961.       XtSetArg (args[0], XtNfromHoriz, button1);
  1962.       XtSetArg (args[1], XtNfromVert, *field2_text);
  1963.       button2 = XtCreateManagedWidget (action2_name, commandWidgetClass, form,
  1964.                        args, TWO);
  1965.       XtAddCallback (button2, XtNcallback, action2, (XtPointer) form);
  1966.     }
  1967.  
  1968.   XtSetArg (args[0], XtNfromHoriz, action2 == NULL ? button1 : button2);
  1969.   XtSetArg (args[1], XtNfromVert, *field2_text);
  1970.   cancelbutton = XtCreateManagedWidget ("abort command", commandWidgetClass,
  1971.                     form, args, TWO);
  1972.   XtAddCallback (cancelbutton, XtNcallback, destroy_popup_prompt,
  1973.          (XtPointer) form);
  1974.  
  1975.   return (popup);
  1976. }
  1977.  
  1978.  
  1979. #ifdef __STDC__
  1980. static void
  1981. warp_to_second_dialog (Widget widget, XEvent *event, String *params,
  1982.                Cardinal *num_params)
  1983. #else
  1984. static void
  1985. warp_to_second_dialog (widget, event, params, num_params)
  1986.      Widget widget;
  1987.      XEvent *event;
  1988.      String *params;
  1989.      Cardinal *num_params;
  1990. #endif
  1991. {
  1992.   Widget form = XtParent (widget);
  1993.   Widget second_dialog;
  1994.  
  1995.   second_dialog = XtNameToWidget (form, "field2_text");
  1996.   if (second_dialog)
  1997.     XWarpPointer (XtDisplay (second_dialog), None, XtWindow (second_dialog),
  1998.           0, 0, 0, 0, 0, 10);
  1999. }
  2000.